package com.homework.dao.impl;

import com.homework.dao.BaseDao;
import com.homework.dao.UserDao;
import com.homework.entity.User;

import java.util.List;

public class UserDaoImpl extends BaseDao implements UserDao {
    @Override
    public int insertUser(User user) {
        String sql="insert into user(username,password,gender,email,telephone,introduce,activeCode,state,role,registTime) value(？，？，？，？，？，？，？，？，？，？)";
        return super.update(sql,user.getUsername(),user.getPassword(),user.getGender(),user.getEmail(),user.getTelephone(),user.getIntroduce(),user.getActiveCode(),user.getState(),user.getRole(),user.getRegistTime());
    }

    @Override
    public int updateUser(User user) {
        String sql="update user username=?,password=?,gender=?,email=?,telephone=?,introduce=?,activeCode=?,state=?,role=?,registTime=? where id=?";
        return super.update(sql,user.getUsername(),user.getPassword(),user.getGender(),user.getEmail(),user.getTelephone(),user.getIntroduce(),user.getActiveCode(),user.getState(),user.getRole(),user.getRegistTime(),user.getId());
    }

    @Override
    public int deleteUser(int userId) {
        String sql="delete from user where id=?";
        return super.update(sql,userId);
    }

    @Override
    public User queryUserNameAndPassword(String username,String password) {
        String sql="select * from user where username=? and password=?";
        return super.queryOne(User.class,sql,username,password);
    }

    @Override
    public List<User> queryAllUser() {
        String sql="select * from user";
        return super.queryMore(User.class,sql);
    }

    @Override
    public User queryUserById(int id) {
        String sql="select * from user where id=?";
        return super.queryOne(User.class,sql,id);
    }
}
